package com.yunxin.core.infra.persistence.repository.contact;

import com.yunxin.core.domain.model.contact.ContactMessageSendSms;
import com.yunxin.core.domain.model.contact.ContactMessageSendSmsRepository;
import com.yunxin.core.infra.persistence.converter.ContactConverter;
import com.yunxin.core.infra.persistence.entity.contact.ContactMessageSendSmsDO;
import com.yunxin.core.infra.persistence.mapper.contact.ContactMessageSendSmsExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class ContactMessageSendSmsRepositoryImpl implements ContactMessageSendSmsRepository {

    private final ContactMessageSendSmsExtendMapper contactMessageSendSmsExtendMapper;

    private final ContactConverter contactConverter;

    @Override
    public boolean saveContactMessageSendSms(ContactMessageSendSms contactMessageSendSms) {
        ContactMessageSendSmsDO contactMessageSendSmsDO = contactConverter.formContactMessageSendSms(contactMessageSendSms);
        int count = contactMessageSendSmsExtendMapper.insertSelective(contactMessageSendSmsDO);
        contactMessageSendSms.setId(contactMessageSendSmsDO.getId());
        return count > 0;
    }

    @Override
    public boolean updateContactMessageSendSms(ContactMessageSendSms contactMessageSendSms) {
        ContactMessageSendSmsDO contactMessageSendSmsDO = contactConverter.formContactMessageSendSms(contactMessageSendSms);
        int count = contactMessageSendSmsExtendMapper.updateByPrimaryKeySelective(contactMessageSendSmsDO);
        return count > 0;
    }

    @Override
    public ContactMessageSendSms getContactMessageSendSmsBySerialNo(String serialNo) {
        ContactMessageSendSmsDO contactMessageSendSmsDO = contactMessageSendSmsExtendMapper.getContactMessageSendSmsBySerialNo(serialNo);
        return contactConverter.toContactMessageSendSms(contactMessageSendSmsDO);
    }
}
